import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCciQe64u4T8oart9jzQ6t71Ym7WB8QYvm06M6kr6vvVLHOTPTGGk39fUYes5m8NTPnDJR/pd0X8LfN2Qh0I/k23MBvlceneHyxJVXb4NhhkHQ5Iewl4pCg5PRJMEmRiS6P6L7vgQcYXGR2pfrfl57y0OYHmcYFq99RLUrTEfd9AwIDAQAB'

const privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJyJB7ri7hPyhqu32PNDq3vVibtYHxBi+bTozqSvq+9Usc5M9MYaTf19Rh6zmbw1M+cMlH+l3Rfwt83ZCHQj+TbcwG+Vx6d4fLElVdvg2GGQdDkh7CXikKDk9EkwSZGJLo/ovu+BBxhcZHal+t+XnvLQ5geZxgWr31EtStMR930DAgMBAAECgYBlNnkIDskPnsYS6/ncOQn9NPIsb2sOhmCc59cNRwUt555cHQg7uzBoUgLvwQMLXX8kys6NxqoxW5UNBWLg7Y2qMU4hDDdVz/CzKzBJ2lzajAyty4Tuauu58R9Be9oV9/PmPJIF0pJ+xoarWlwY0l4wMA6obbEKhx3h+ArYMILeqQJBAPnKSXnN6ctnjegIx7MUfmOj4F/Y4+G/hnn6Rr7AxeXeOI21SdNiD1/6xIExTaVE0bAh7nh7VtGtFsT+G6MTWUUCQQCgbUA8Xd6FXrneKPOcu8fQiacChPevHQl/QxfwEmrU+uqH56NqTnL5caQSxorVUUmiJ0Z0rtcifvhh7V8SLM2nAkAvy6EbiWb+4KWqjGOJxJYagrTgIiQYggk9NcJrpX84aLjxhIrHw6+lcdo/zitJQE3PIe77Zr5KCJCeyPCI157xAkAkQq1bN6hdIt0GDuGJUpRGWWarVhyZswl7f1HAzJjjDNfH4h54n8SzBvGb4M5uitIG2bO+Geq8fFBt6fYsKH5PAkEAkZopkeBaTGHuM7RjCJoi/YC82fjvWOD9o8bSvxOxjqjrd+GZtJWOyIKVNWNri+5sYQY/Hql/MNUO0mJ3MQX5+w=='

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey)
  return encryptor.decrypt(txt)
}

